#!/usr/bin/python3
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t -*-

import os


class WrtConst:

    MY_NAME = "wrtd"
    MY_GROUP = "wrtd"

    PLUGIN_TYPE_CONNECTION = 1
    PLUGIN_TYPE_PRIVNET = 2
    PLUGIN_TYPE_SUBNET_L2 = 3
    PLUGIN_TYPE_SUBNET_L3 = 4
    PLUGIN_TYPE_SELECTOR = 5

    CONNECTION_LEVEL_1 = "1"
    CONNECTION_LEVEL_2 = "2"

    CONNECTION_LEVEL_1_USER = "wrtd-connection-level-1"
    CONNECTION_LEVEL_2_USER = "wrtd-connection-level-2"

    etcDir = os.path.join("/etc", MY_NAME)
    libDir = os.path.join("/usr", "lib64", MY_NAME)
    libexecDir = os.path.join("/usr", "libexec", MY_NAME)
    dataDir = os.path.join("/usr", "share", MY_NAME)
    runDir = os.path.join("/run", MY_NAME)
    logDir = os.path.join("/var", "log", MY_NAME)
    tmpDir = os.path.join("/tmp", MY_NAME)
    varDir = os.path.join("/var", MY_NAME)

    procIpForwareFile = "/proc/sys/net/ipv4/ip_forward"
    connectionPluginSocketFilePattern = os.path.join(runDir, "connection-plugin-lv%s.socket")

    pidFile = os.path.join(runDir, "%s.pid" % (MY_NAME))

    nameServerSocketFileLv2 = os.path.join(runDir, "nameserver-lv2.socket")
    nameServerSocketFile = os.path.join(runDir, "nameserver.socket")

    @staticmethod
    def isPluginTypeValid(pluginType):
        return pluginType in [
            WrtConst.PLUGIN_TYPE_CONNECTION,
            WrtConst.PLUGIN_TYPE_PRIVNET,
            WrtConst.PLUGIN_TYPE_SUBNET_L2,
            WrtConst.PLUGIN_TYPE_SUBNET_L3,
        ]

    @staticmethod
    def isConnnectionLevelValid(level):
        return level in [
            WrtConst.CONNECTION_LEVEL_1,
            WrtConst.CONNECTION_LEVEL_2,
        ]


class WrtParam:

    def __init__(self):

        self.globalCfgFile = os.path.join(WrtConst.etcDir, "global.cfg")

        self.dataFile = os.path.join(self.varDir, "global.json")

        self.uuid = None

        self.mntNs = None
        self.netNs = None

        self.pluginHub = None
        self.prefixPool = None

        self.mainloop = None

        self.abortOnError = False
        self.logLevel = None
        self.config = None

        # business object
        self.wcoreLv01 = None
        self.wcoreLv02 = None
        self.wcoreLv99 = None
        self.selectorLv01 = None
        self.selectorLv02 = None
        self.selectorLv99 = None
